/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.amuthu.expression.function.indicator;

import org.amuthu.DataStore;
import org.amuthu.expression.Expression;
import org.amuthu.expression.exception.InvalidArgumentException;
import org.amuthu.parser.ExpressionVisitor;

/**
 *
 * @author prabhu
 */
public abstract class BaseIndicatorFunction extends AbstractFunctionEvaluator
{
   @Override
   public boolean updateParameters(DataStore dataStore, Expression[] arguments, ExpressionVisitor visitor)
   {
      return doUpdateParameters(dataStore, arguments, visitor);
   }

   public double computeIndicator(DataStore dataStore, Expression[] arguments, ExpressionVisitor visitor) throws InvalidArgumentException
   {
      if (!updateParameters(dataStore, arguments, visitor))
      {
         throw new InvalidArgumentException("Function zero args");
      }
      return calculateIndicator(dataStore, arguments, visitor);
   }

   public int computeDayDependency(DataStore dataStore, Expression[] arguments, ExpressionVisitor visitor) throws InvalidArgumentException
   {
      if (!updateParameters(dataStore, arguments, visitor))
      {
         throw new InvalidArgumentException("Function zero args");
      }
      return calculateDependency(dataStore, arguments, visitor);
   }

   abstract public double calculateIndicator(DataStore dataStore, Expression[] arguments, ExpressionVisitor visitor);

   abstract public int calculateDependency(DataStore dataStore, Expression[] arguments, ExpressionVisitor visitor);

   abstract public boolean doUpdateParameters(DataStore dataStore, Expression[] arguments, ExpressionVisitor visitor);

}
